package com.car.advertising;

import android.content.Context;

import com.car.advertising.db.DaoMaster;
import com.car.advertising.db.DaoSession;
import com.car.advertising.map.GaoDeMap;
import com.support.widget.ViewApplication;

/**
 * 开发者：LuoYi
 * Time: 2017 10:29 2017/3/31 03
 */

public class CarApplication extends ViewApplication {

    public static String token;// token

    public static CarApplication instance = null;

    private static DaoMaster daoMaster;
    private static DaoSession daoSession;



    @Override
    public void onCreate() {
        super.onCreate();
        instance = this;
        GaoDeMap.getInstance().initMap(getApplicationContext());
    }

    public static CarApplication getInstance() {
        return instance;
    }

    /**
     * 取得DaoMaster
     *
     * @param context
     * @return
     */
    public static DaoMaster getDaoMaster(Context context) {
        if (daoMaster == null) {
            DaoMaster.OpenHelper helper = new DaoMaster.DevOpenHelper(context, "QianBaoShangJia", null);
            daoMaster = new DaoMaster(helper.getWritableDatabase());
        }
        return daoMaster;
    }

    /**
     * 取得DaoSession
     *
     * @param context
     * @return
     */
    public static DaoSession getDaoSession(Context context) {
        if (daoSession == null) {
            if (daoMaster == null) {
                daoMaster = getDaoMaster(context);
            }
            daoSession = daoMaster.newSession();
        }
        return daoSession;
    }

}
